#version 460
#extension GL_GOOGLE_include_directive : enable
#extension GL_EXT_nonuniform_qualifier : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require
#extension GL_EXT_shader_explicit_arithmetic_types_int16 : require

#include "../../../../core/shader_binding_ID.h"
#include "../../../../core/shader_std.h"
#include "../../../../core/shader_built_in_functions.h"

#include "PBR_MaterialAtt.glsl"



layout(location=0) out vec4 outColor;

layout(set = 1, binding = DEF_BINDING_WIDGET_Texture) uniform sampler2D texColor[];
//layout(std430, set = 1, scalar, column_major, binding = DEF_BINDING_TasterBindID_MaterialID) readonly buffer Buf {
//	S_Material gMaterial[];
//};
//layout(set = 2, binding = DEF_BindID_TextureCube) uniform samplerCube texEnv[];

layout(location = 0) in vec3 inEyeDir;
layout(location = 1) in vec3 inNormal;
layout(location = 2) in vec4 inVert;
//layout(location = 3) in mat4 inProj;
layout(location = 7) in flat uint inMaterialID;


//layout(set = 2, binding = DEF_BindID_TextureCube) uniform samplerCube texEnv[];
//layout(set = 2, binding = DEF_BindID_TextureShadow) uniform sampler2D texShadow[];
//layout(set = 2, binding = DEF_BindID_TexCubeShadow) uniform samplerCube texCubeShadow[];
//layout(set = 2, binding = DEF_BindID_GBufferImage)  uniform sampler2D GBuffer_Image[];
//layout(set = 2, binding = DEF_BindID_CompositingShadow) uniform sampler2D compositing_shadow[];

/*
layout(std140, set = 2, scalar, binding = DEF_BindID_GlobalTextAtt) uniform Buf0 {
	S_GlobalAtt_RasterPostCompositing m_constPush;
};

//每个灯光的阴影图层数量
layout(std430, set = 2, column_major, scalar, binding = DEF_BindID_TexShadow_LightIndex) readonly buffer Buf1 {
	S_LightIndex m_LightIndex[];
};

//光投影矩阵
layout(std430, set = 2, column_major, scalar, binding = DEF_BindID_TexShadow_PVMatrix) readonly buffer Buf3 {
	mat4 m_LightArea_PVMatrix[];
};

//区域光属性
layout(std430, set = 2, column_major, scalar, binding = DEF_BindID_TexShadow_AreaLight) readonly buffer Buf2 {
	S_LightArea m_LightArea[];
};
*/

layout(std430, set = 2, scalar, column_major, binding = DEF_BINDING_TasterBindID_MaterialID) readonly buffer Buf4 {
	S_Material gMaterial[];
};




void main(void){
	//float sampleDelta = 0.5;
	//for(float phi = 0.0; phi < 2.0 * M_PI; phi += sampleDelta) {
	//	for(float theta = 0.5; theta < 0.5 * M_PI; theta += sampleDelta) {
	//		vec3 SampleVec = f_SphereSampling(vec2(theta, phi));
	//		SampleVec = normalize(f_SphereSampling_toWorld(SampleVec, inNormal));
	//	}
	//}
	S_Material mate = gMaterial[inMaterialID];

	//float intensity = mate.m_emission.r / 256.0;

	outColor.a = mate.m_emission.r;
	//outColor.a = int(10);
	outColor.rgb = mate.m_color;
	//outColor.rgb = vec3(0,1,0);
	//outColor.rgb = mate.m_emission;
	

	//outColor = vec4(vec3(dot(inEyeDir, inNormal)),1);
	//outColor = vec4(1);


	//vec3 rv = reflect(normalize(-inEyeDir), inNormal);
	//outColor += texture(texEnv[0], rv) * 0.8;
	//outColor += texture(texEnv[0], normalize(inEyeDir));
	//outColor += texture(texEnv[0], inNormal);
	//if(inVert.z < 0){
	//	//outColor.xyz += normalize(inVert);
	//	outColor.z += 0.1;
	//}else{
	//
	//}
	//outColor += texture(texEnv[nonuniformEXT(0)], normalize(inVert)) * 0.8;
	
	//outColor.xyz += normalize(inEyeDir);
	//outColor.xyz += normalize(inNormal);
	//outColor.xyz += normalize(rv);
	//outColor += texture(texEnv[0], vec3(1,0,0));
}



